function getMyDate(){
    var myDate = new Date();
    var year = myDate.getFullYear(); // 获取当前年份
    var month = myDate.getMonth() + 1; // 获取当前月份(0-11,0代表1月所以要加1);
    if(month < 10){
        month = "0" + month;
    }
    var day = myDate.getDate(); // 获取当前日（1-31）
    if(day < 10){
        day = "0" + day;
    }
    return year+"-"+month+"-"+day;
}

//将时间转换
function todate(inputstr) {
    if(!inputstr){
        return null;
    }
    // Wed Mar 22 13:38:37 CST 2017
    // Wed May 19 2021 00:00:00 GMT+0800 (中国标准时间)
    inputstr = inputstr + ""; //末尾加一个空格
    var date = "";
    var month = new Array();
    month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["Apr"] = 4; month["May"] = 5; month["Jun"] = 6;
    month["Jul"] = 7; month["Aug"] = 8; month["Sep"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12;
    var str = inputstr.split(" ");
    var adate = str[2];
    var ayear = str[3];
    var amonth = month[str[1]];
    if(amonth < 10){
        amonth = "0" + amonth;
    }
    if(adate < 10 && adate.length == 1){
        adate = "0" + adate;
    }
    return ayear+"-"+amonth+"-"+adate;
}

$(function () {
    let url = '../userRecord/list?types=4';
    $("#jqGrid").Grid({
        url: url,
        colModel: [
            {label: 'id', name: 'reportId', index: 'reportId', key: true, hidden: true},
            // {label: '是否认证', name: 'openBank', index: 'open_bank', width: 40},
            // {label: '提现状态', name: 'openBank', index: 'open_bank', width: 40},
            {label: '用户id', name: 'userId', index: 'user_id', width: 20},
            {label: '会员名称', name: 'userName', index: 'userName', width: 50},
            {label: '姓名', name: 'realName', index: 'real_name', width: 30},
            {label: '证件号码', name: 'idCard', index: 'id_card', width: 60},
            {label: '银行卡号', name: 'bankCard', index: 'bank_card', width: 60},
            {label: '手机号', name: 'mobile', index: 'mobile', width: 40},
            {label: '提现金额', name: 'price', index: 'price', width: 30},
            {label: '实际提现金额', name: 'realPrice', index: 'realPrice', width: 30},
            {label: '实际发放金额（元）', name: 'realOut', index: 'realOut', width: 30},
            {label: '发放金额（元）', name: 'out', index: 'out', width: 30},
            {label: '可用余额', name: 'amount', index: 'amount', width: 30},
            {
                label: '提现申请时间', name: 'ctime', index: 'ctime', width: 50, formatter: function (value) {
                    return transDate(value);
                }
            },{label: '是否被驳回', name: 'refund', index: 'refund', width: 30},]
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        showRefundCash: false,
        title: null,
        userRecord: {},
        userRecordRefundCash: {},
        q: {
            userId: '',
            cTime: null
        },
        ruleValidateRefundCash: {
            points: [
                {required: true, message: '驳回理由不能为空', trigger: 'blur'}
            ]
        },
    },
    // mounted: function() {
    //     this.q.cTime = getMyDate();
    // },
    methods: {
        query: function () {
            vm.reload();
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                url: '../userRecord/list?types=4',
                postData: {'userId': vm.q.userId, 'cTime': todate(vm.q.cTime)},
                page: page
            }).trigger("reloadGrid");
        },
        exportUserRecordCash: function () {
            exportFile('#rrapp', '../userRecord/export?types=4', {'userId': vm.q.userId, 'cTime': todate(vm.q.cTime)});
        },
        clickRefundCash: function (event) {
            var selectdata = getSelectedRowData("#jqGrid");
            if(selectdata.refund == '是'){
                alert('该记录已经被驳回，不能重复操作！');
                return;
            }
            vm.showRefundCash = true;

            Ajax.request({
                url: "../userRecord/info/" + selectdata.reportId,
                async: true,
                successCallback: function (r) {
                    vm.userRecordRefundCash = r.userRecord;
                }
            });
        },
        refundCash: function (event) {
            confirm('确定要驳回吗？', function () {
                Ajax.request({
                    type: "POST",
                    url: "../userRecord/refundCash",
                    contentType: "application/json",
                    params: JSON.stringify(vm.userRecordRefundCash),
                    successCallback: function (r) {
                        alert('操作成功', function (index) {
                            vm.reloadRefundCash();
                        });
                    }
                });
            });
        },
        reloadRefundCash: function (event) {
            vm.showList = true;
            vm.showRefundCash = false;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                url: '../userRecord/list?types=4',
                postData: {'userId': vm.q.userId, 'cTime': todate(vm.q.cTime)},
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidateRefundCash');
        },
        handleSubmitRefundCash: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.refundCash()
            });
        }
    }
});